package org.dormi.learn.domain;


import org.dormi.learn.BaseSerializable;

import java.util.Objects;

/**
 * 事务代码
 *
 * @author : dormi330
 * @version : 1.0
 */
public class Tcode extends BaseSerializable {

    public static final String VERSION_1_0 = "1.0";

    private final String version;
    private final String code;

    /* === constructor === */
    /* === constructor === */
    /* === constructor === */

    private Tcode(String code, String version) {
        this.code = code;
        this.version = version;
    }

    private Tcode(String code) {
        this(code, VERSION_1_0);
    }

    public static Tcode from(String code) {
        return new Tcode(code);
    }

    public static Tcode from(Class clazz) {
        return Tcode.from(clazz.getSimpleName());
    }

    /* === hash/equals === */
    /* === hash/equals === */
    /* === hash/equals === */

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Tcode)) return false;
        Tcode tcode = (Tcode) o;
        return Objects.equals(getVersion(), tcode.getVersion()) &&
                Objects.equals(code, tcode.code);
    }

    @Override
    public int hashCode() {
        return Objects.hash(getVersion(), code);
    }

    /* === set/get === */
    /* === set/get === */
    /* === set/get === */

    public String code() {
        return code;
    }

    public String getVersion() {
        return version;
    }
}